﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ARSys.Entity;

namespace Wicresoft.Task.ARNotice.Emails
{
    class PendingForApproval : EmailTemplate
    {
        public PendingForApproval(Email armail, ARSysContext dc, params object[] entities)
            : base(armail, dc, entities)
        {

        }

        public override string[] To
        {
            get
            {
                // 如果AssignedGroup是Business Manager，则To给Assigned
                if (String.IsNullOrEmpty(armail.AssignedGroupId) || 
                    armail.AssignedGroup == "Business Manager")
                {
                    // get assigned guy
                    var sql = from people in dc.People
                              where people.CIL == armail.Assigned
                              select people.Email;
                    return sql.ToArray();
                }
                else
                {
                    // get assigned group
                    var sql = from people in dc.People
                              from role in dc.Groups
                              from pg in dc.PGAssociations
                              where people.PeopleId == pg.PeopleId
                              where role.GroupId == pg.GroupId
                              where role.GroupId == armail.AssignedGroupId
                              select people.Email;

                    return sql.ToArray();
                }
            }
        }

        public override string[] Cc
        {
            get
            {
                // get applicant guy
                return TryGetReceptions(armail.Applicant);
            }
        }

    }
}
